package cn.wolfcode.trip.app.controller;


import cn.wolfcode.trip.base.domain.*;
import cn.wolfcode.trip.base.query.ProductQueryObject;
import cn.wolfcode.trip.base.service.IProductSortService;
import cn.wolfcode.trip.base.service.IProductService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品资源控制器
 */
@RestController
@RequestMapping("/products")
public class ProductController {

    @Autowired
    private IProductService productService;

    @Autowired
    private IProductSortService productSortService;
    /**
     * 获取全部商品明细
     * @param qo
     * @return
     */
    @GetMapping
    public PageInfo queryForList(ProductQueryObject qo){
        PageInfo<Product> list = productService.query(qo);
        return list;
    }

    /**
     * 根据商品分类获取商品明细
     * @param qo
     * @return
     */
    @GetMapping("/{sortId}/product")
    public PageInfo selectBySortId(ProductQueryObject qo){
        PageInfo<Product> list = productService.query(qo);
        return list;
    }

    /**
     * 根据商品id获取商品内容
     */
    @GetMapping("/{productId}")
    public Product selectProductById(@PathVariable Long productId){
        return productService.selectProductById(productId);
    }
}
